<template>
	<view style="padding-top: 30rpx;height: 100vh;">
		<uni-swipe-action>
			<uni-swipe-action-item :right-options="options" @click="swipeChange(i,item.id)" v-for="(item,i) in list">
				<view class="flex oneLine">
					<view>
						<image v-if="item.type=='支付宝'" src="https://wx.2024csnl.com/static/mine/zhifubao.png"></image>
						<image v-if="item.type=='银行卡'" src="https://wx.2024csnl.com/static/mine/zhanghao.png"></image>
					</view>
					<view>
						<view v-if="item.type=='银行卡'" style="margin-bottom: 10rpx;">{{item.name}}</view>
						<view v-if="item.type=='支付宝'">支付宝</view>
						<view>{{item.account}}</view>
					</view>
					
				</view>
			</uni-swipe-action-item>
		</uni-swipe-action>
		<view class="flex-center addressImgBox" v-if="list.length==0">
			<image src="https://wx.2024csnl.com/static/noData.png"></image>
			暂无账号~
		</view>

		<view class="flex-center">
			<button class="set-btn" form-type="submit"
				@click="onSkip(`/package/mine/accountManagement/addAccount`)">添加</button>
		</view>
	</view>
</template>

<script>
	import {
		getAccount,
		delAccountNumber
	} from "../../../api/index.js"
	export default {
		data() {
			return {
				list: [],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#FF0000'
					}
				}],
			}
		},
		onShow() {
			this.getAccount()
		},
		methods: {
			async swipeChange(index, id) {
				const res = await delAccountNumber(`s=/ApiBusiness/deleteaccount`, {
					id:id
				})
				const {
					status,
					msg
				} = res.data
				this.showToast(msg)
				if (status == 1) {
					setTimeout(()=>{
						this.getAccount()
					},2000)
				} 
				// console.log(index,id)
			},
			async getAccount() {
				const res = await getAccount(`s=/ApiBusiness/getaccount`)
				const {
					status,
					data,
					msg
				} = res.data
				if (status == 1) {
					this.list = data
					console.log(res.data)
				} else {
					this.showToast(msg)
				}
			},

		}
	}
</script>

<style>
	page {
		background: #f7f7f7;
	}
</style>
<style lang="scss" scoped>
	.addressImgBox {
		flex-direction: column;
		color: #999;
		padding-top: 20%;

		image {
			width: 400rpx;
			height: 400rpx;
		}
	}

	.set-btn {
		position: fixed;
		bottom: 30rpx;
		width: 90%;
		height: 96rpx;
		line-height: 96rpx;
		border-radius: 18rpx;
		color: #FFFFFF;
		font-weight: bold;
		background: #41644A;
	}

	.oneLine {
		background: #fff;
		align-items: center;
		padding: 30rpx 50rpx;
		border-bottom: 1px solid #f5f5f5;
	}

	image {
		width: 65rpx;
		height: 65rpx;
		margin-right: 30rpx;
	}
</style>
